import {arrayToMap, deleteSql, insertSql, objectToMap, selectSql} from "../util/sqlUtils";
import {Msg} from "../sql/domin";


export class MsgMapper{

    public static deleteCheckedMsg(targetId:number){
        return deleteSql('msg',new Map<string,any>([
            ['targetId',targetId],
            ['msgType','1']
        ]))
    }

    public static insertMsg(msg:Msg[]){
        return insertSql('msg',arrayToMap(msg.map(it=>{
            return {
                id:it.id,
                content:it.content,
                msgType:it.msgType,
                sendId:it.sendId,
                targetId:it.targetId,
                contentId:it.contentId,
                msgStatus:it.msgStatus,
            } as Msg
        })))
    }

    public static selectMsg(msg:Msg){
        return selectSql('msg',objectToMap(msg) as Map<string,any>)
    }

}
